package com.tma.internship.ClassesInfo;

import java.io.File;
import java.util.List;

import com.tma.internship.activities.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListFileAdapter extends ArrayAdapter<FileInfo> {
	private int resID;
	public ListFileAdapter(Context context, int textViewResourceId, List<FileInfo> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
		resID = textViewResourceId;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		//return super.getView(position, convertView, parent);
		View v = convertView;
		if (v == null){
			LayoutInflater mInflater = LayoutInflater.from(getContext());
			v = mInflater.inflate(resID, null);
		}
		FileInfo fInfo = getItem(position);
		TextView fName = (TextView) v.findViewById(R.id.fname);
		TextView fSize = (TextView) v.findViewById(R.id.fsize);
		TextView fPage = (TextView) v.findViewById(R.id.fpage);
		TextView fAvail = (TextView) v.findViewById(R.id.favailable);
		ImageView img = (ImageView) v.findViewById(R.id.download_file_img);
		fName.setText(fInfo.getName());
		fSize.setText(getContext().getString(R.string.size)+fInfo.getSize());
		fPage.setText(getContext().getString(R.string.page)+fInfo.getNumOfPage());
		img.setImageDrawable(fInfo.getImg());
		if (!fInfo.isStored())
			fAvail.setText(getContext().getString(R.string.available));
		else fAvail.setText(getContext().getString(R.string.downloaded));
		return v;
	}
	
}
